package com.checkoutcheckins.client.panels;

import com.checkoutcheckins.client.callbacks.MessageTimer;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;

public class StatusPanel extends HorizontalPanel {

	private HTML message;

	private Image loadIcon;

	private HorizontalPanel hp;

	private boolean inTimer = false;

	private String queueMessage = null;

	private Boolean queueTimer;

	public StatusPanel() {
		super();
		init();
	}

	private void init() {
		this.setHorizontalAlignment(ALIGN_CENTER);
		message = new HTML("");
		loadIcon = new Image("images/infogreenload.gif");
	}

	public void showLoadMessage(String text, boolean timer) {
		if (!inTimer) {
			this.clear();
			hp = new HorizontalPanel();
			this.setStyleName("statusPanelLoad");
			message.setHTML(text);
			hp.add(message);
			hp.add(loadIcon);
			this.add(hp);
			if (timer) {
				inTimer = true;
				System.out.println("Starting timer");
				Timer t = new MessageTimer(this);
				t.schedule(3000);
			}
		} else {
			System.out.println("adding " + text + " to queue");
			queueMessage = text;
			System.out.println("timer is " + timer);
			queueTimer = timer;
		}
	}

	public void showErrorMessage(String text, boolean retry) {
		this.clear();
		hp = new HorizontalPanel();
		this.setStyleName("statusPanelError");
		message.setHTML(text);
		hp.add(message);
		if (retry) {
			hp.add(loadIcon);
		}
		this.add(hp);
	}

	public String getQueueMessage() {
		return queueMessage;
	}

	public boolean isInTimer() {
		return inTimer;
	}

	public void setInTimer(boolean inTimer) {
		this.inTimer = inTimer;
	}

	public boolean getQueueTimer() {
		return queueTimer;
	}

	public void setQueueMessage(String queueMessage) {
		this.queueMessage = queueMessage;
	}

	public void setQueueTimer(Boolean queueTimer) {
		this.queueTimer = queueTimer;
	}

}
